#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
# @version: v1.0
# @author : wlisingle
# @Email : 19688513@qq.com
# @Project : g-carbon-bio
# @File : stock_analysis_result.py
# @Software: PyCharm
# @time: 2025/3/3 11:03
# @description : 导出csv 内容的类
"""

class StockAnalysisResult:
    def __init__(self, first_date, first_amount, second_date, second_amount, third_date, third_amount, code, second_ratio, third_ratio, next_day_date=None, next_day_change_percent=None, ma5=None, ma10=None, ma20=None, ma30=None, ma60=None, ma120=None, latest_price=None):
        """
        股票分析结果模型类

        :param first_date: 第一日期
        :param first_amount: 第一数量
        :param second_date: 第二日期
        :param second_amount: 第二数量
        :param third_date: 第三日期
        :param third_amount: 第三数量
        :param code: 股票代码
        :param second_ratio: 第二量比
        :param third_ratio: 第三量比
        :param next_day_date: 次日日期
        :param next_day_change_percent: 次日涨跌幅
        :param ma5: 5日均线
        :param ma10: 10日均线
        :param ma20: 20日均线
        :param ma30: 30日均线
        :param ma60: 60日均线
        :param ma120: 120日均线
        :param latest_price (float): 最新价
        """
        self.first_date = first_date
        self.first_amount = first_amount
        self.second_date = second_date
        self.second_amount = second_amount
        self.third_date = third_date
        self.third_amount = third_amount
        self.code = code
        self.second_ratio = second_ratio
        self.third_ratio = third_ratio
        self.next_day_date = next_day_date
        self.next_day_change_percent = next_day_change_percent
        self.ma5 = ma5
        self.ma10 = ma10
        self.ma20 = ma20
        self.ma30 = ma30
        self.ma60 = ma60
        self.ma120 = ma120
        self.latest_price = latest_price

    def to_list(self):
        """
        将对象数据转换为列表格式，以便写入 CSV 文件
        :return: 列表格式的数据
        """

        # 判断 latest_price 是否超过各个均线
        def check_break(ma):
            if self.latest_price is not None and ma is not None:
                return "穿" if self.latest_price > ma else "未穿"
            return "无数据"

        # 返回的列表
        return [
            self.code, self.second_ratio, self.third_ratio,
            self.next_day_date.strftime('%Y-%m-%d') if self.next_day_date else '无数据',
            self.next_day_change_percent if self.next_day_change_percent is not None else '无数据',
            self.latest_price if self.latest_price is not None else '无数据',  # 最新价
            self.ma5, check_break(self.ma5),  # 5日均线及是否突破
            self.ma10, check_break(self.ma10),  # 10日均线及是否突破
            self.ma20, check_break(self.ma20),  # 20日均线及是否突破
            self.ma30, check_break(self.ma30),  # 30日均线及是否突破
            self.ma60, check_break(self.ma60),  # 60日均线及是否突破
            self.ma120, check_break(self.ma120),  # 120日均线及是否突破
            self.first_date.strftime('%Y-%m-%d'), self.first_amount,
            self.second_date.strftime('%Y-%m-%d'), self.second_amount,
            self.third_date.strftime('%Y-%m-%d'), self.third_amount,
        ]
